Home > Backend Development > PHP Tutorial > Detailed explanation of 'continue' examples of PHP jumping out of loops

Detailed explanation of 'continue' examples of PHP jumping out of loops

怪我咯
Release: 2023-03-07 13:38:01
Original
3029 people have browsed it

After learning "break" to jump out of the loop, let's learn our "continue" to jump out of the loop.

continue is not as powerful as break to jump out of the loop. continue can only terminate this cycle and enter the next cycle.

The difference between break and continue is like ours It's like playing chess. Some people are not good at chess. When they see that they are about to lose, they turn off the chessboard and stop playing. This is a break. Some people know that if you lose this sentence, the next one will not win. If you admit defeat and try another game, this is continue.

continue control flow chart is as follows:

Detailed explanation of continue examples of PHP jumping out of loops

continue to jump out of the loop instance, The code is as follows

<?php   
  
for($i=0;$i<2;$i++)  
{  
    for($j=1;$j<4;$j++)  
    {  
        if($j==2)  
        {  
            continue 2;   //跳出最近的一个for循环的2次循环(j=2和j=3)  
        }  
    echo &#39;$i=&#39;.$i.&#39;$j=&#39;.$j."<br>";  
    }  
}  
 ?>
Copy after login

Code running results:

Detailed explanation of continue examples of PHP jumping out of loops

Detailed example explanation:

First execute the outermost loop of $i=0, and then execute $ j, when executing to $j==2 and encountering continue 2, it will jump out of the last 2 loops of the for loop, so j=2 cannot be printed,


The above is the detailed content of Detailed explanation of 'continue' examples of PHP jumping out of loops. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template